// pages/company/teamwork/teamwork.js
const App = getApp()
// let AJAX = require("../../../utils/util.js").AJAX
// let formatRichText = require('../../../utils/util.js').formatRichText
let { AJAX, formatRichText, imgUrl } = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navH:"",
    dataInfo:'',
     uname: '', // 留言用户
     uphone: '', // 用户电话
     umsg: '', // 用户留言,
    imgUrl: imgUrl
  }, 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      navH: App.globalData.navHeight
    })
     if (!wx.getStorageSync("ACCESSTOKEN")) {
        App.userInfoReadyCallback = res => {
           wx.setStorageSync('ACCESSTOKEN', res);
           this.requestInfo()
        }
        return
     }
    this.requestInfo()
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
   /**留言 */
   confirmMsg() {
      let vm = this
      AJAX('applicant/submit-applicant', 'POST', {
         applicant_type: 'business',
         applicant_name: this.data.uname,
         applicant_phone: this.data.uphone,
         applicant_message: this.data.umsg
      }).then(res => {
         if (res.status === 'succeed') {
            wx.showToast({
               title: '留言成功，我们将尽快与您联系',
               icon: "none"
            })
            this.setData({
               contact: false
            })

         }
      })

   },
   inputInfo(e) {
      this.setData({
         uname: e.detail.value
      })
      //console.log(e.detail.value)
   },
   inputInfoPhone(e) {
      this.setData({
         uphone: e.detail.value
      })
      //console.log(e.detail.value)
   },
   inputInfoMsg(e) {
      this.setData({
         umsg: e.detail.value
      })
      //console.log(e.detail.value)
   },


  requestInfo(){
    let vm =this
    AJAX("contact/list").then(res=>{
      let _data = res.data[0]
      _data.detail = formatRichText(_data.detail).replace(/<section/g, '<div').replace(/\/section>/g, '\div>')
      vm.setData({
        dataInfo:_data
      })
    })
  },
  navBack(){
    wx.navigateBack()
  },
  codeRead(e){
    let _url = e.currentTarget.dataset.url
    wx.previewImage({
      urls: [_url],
    })
  },
  makePhone(e) {
    let _phone = e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: _phone,
    })
  },
  wechartTap(e){
    let _url = e.currentTarget.dataset.url
    wx.previewImage({
      urls: [_url],
    })
  }
})